package upcweb.dao;

import java.sql.ResultSet;
import java.util.ArrayList;

import upcweb.modelo.ClsUsuario;

public class UsuarioDAO {

	SQLProcDAO sql= new SQLProcDAO();
	
	public ClsUsuario getUserByName(ClsUsuario user){
		ClsUsuario us = null;
		try {
			System.out.println("USER: "+user.getNo_usuario());
			ResultSet rs = sql.getData("{call sp_get_user_by_name (?,?,?)}", 
					new Object[]{user.getNo_usuario(), user.getNo_pwd(), user.getCheck()});
			if (rs.next()){
				us = new ClsUsuario();
				us.setCo_estado(rs.getString("fl_status"));
				us.setNo_usuario(user.getNo_usuario());
				us.setCo_responsable(rs.getInt("co_responsable"));
				us.setNu_documento(rs.getString("nu_documento"));
				us.setNo_responsable(rs.getString("no_responsable")+" "+rs.getString("ape_paterno")+rs.getString("ape_materno"));
				us.setCo_sexo(rs.getString("co_sexo"));
				us.setNu_celular(rs.getString("nu_celular"));
				us.setNo_correo(rs.getString("no_correo"));	
				//System.out.println("FOUND");
			}
			else {
				us = null;
				//System.out.println("NOT FOUND");
			}
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println(e.getMessage());
		}
		return us;
	}
	
	public ArrayList<ClsUsuario> getUsuariosActivos(){
		ArrayList<ClsUsuario> arr= new ArrayList<ClsUsuario>();
		try {
			ResultSet rs = sql.getData("select a.no_usuario, count(*) actividad from infocomentario a inner join usuario b on a.no_usuario = b.no_usuario group by a.no_usuario",
					new Object[]{});
		} catch (Exception e) {
			// TODO: handle exception
			System.err.println(e.getMessage());
		}
		return arr;
	}
	
}
